package Memento;

public class Client {
    private static int index = 0;
    private static CaretakerChess caretakerChess = new CaretakerChess();

    public static void play(OriginatorChess chess)
    {
        System.out.println("落子");
        index++;
        caretakerChess.addMem(chess.saveToMemento());
        chess.show();
    }

    public static void undo(OriginatorChess chess)
    {
        System.out.println("悔棋");
        index--;
        chess.restore(caretakerChess.getMem(index-1));
        chess.show();
    }

    public static void redo(OriginatorChess chess)
    {
        System.out.println("撤销悔棋");
        chess.restore(caretakerChess.getMem(index));
        index++;
        chess.show();
    }


    public static void main(String[] args) {
        OriginatorChess chess = new OriginatorChess(new MementoChess("黑",3,4));

        play(chess);
        chess.setX(6);
        play(chess);
        chess.setY(3);
        play(chess);
        undo(chess);
        undo(chess);
        redo(chess);
        redo(chess);
    }
}
